package com.andaily.web.controller.mobile.thing;

import com.andaily.domain.dto.thing.ThingDto;
import com.andaily.domain.dto.thing.ThingWarningDto;
import com.andaily.domain.thing.ThingStatus;
import com.andaily.service.ThingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author Shengzhao Li
 */
@Controller
@RequestMapping("/thing/warning")
public class ThingWarningController {

    @Autowired
    private ThingService thingService;


    @RequestMapping("overview")
    public String overview(ThingWarningDto thingWarningDto, Model model) throws Exception {
        thingWarningDto = thingService.loadThingWarningDto(thingWarningDto);
        model.addAttribute("thingWarningDto", thingWarningDto);
        return "thing/thing_warning_overview";
    }

    @RequestMapping("overview/more")
    public String more(ThingWarningDto thingWarningDto, Model model) throws Exception {
        thingWarningDto = thingService.loadThingWarningDto(thingWarningDto);
        model.addAttribute("thingWarningDto", thingWarningDto);
        return "thing/thing_warning_overview_more";
    }

    @RequestMapping("action/{guid}")
    public String action(@PathVariable() String guid, Model model) throws Exception {
        ThingDto thingDto = thingService.loadExistThingDto(guid);
        model.addAttribute("thingDto", thingDto);
        return "thing/thing_warning_action";
    }

    @RequestMapping("changestatus/{guid}/{status}")
    public String changeStatus(@PathVariable("guid") String guid, @PathVariable("status") ThingStatus status) {
        thingService.changeThingStatus(guid, status);
        return "redirect:../../overview?result=true";
    }


}
